package com.xsmart.goods.services.wx;

import com.xsmart.common.constant.ResultConstant;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.goods.dao.wx.WxIndexDataDao;
import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class WxIndexService {
    @Autowired
    WxIndexDataDao wxIndexDataDao;

    /**
     * 查询首页数据
     *
     * @param requestBean 请求对象
     * @return 返回对象
     */
    public ResponseBean queryIndexData(RequestBean requestBean) {
        ResponseBean responseBean = requestBean.getResponseBean();
//        //首页顶部轮播图片  ggtop
//        List<Map<String, Object>> ggtop = wxIndexDataDao.queryIndex("main_top",1);
//        //首页推荐品牌 20个
//        List<Map<String, Object>> brand = wxIndexDataDao.queryIndexBrand();
//        //首页推荐产品
//        List<Map<String, Object>> proList = wxIndexDataDao.queryIndex("main_product",3);
//        responseBean.addResultItem("ggtop", ggtop);
//        responseBean.addResultItem("brand", brand);
//        responseBean.addResultItem("prolist",proList);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 查询推荐对象
     * @param requestBean
     * @return
     */
    public ResponseBean queryPriority(RequestBean requestBean) {
        Date now=new Date();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String seatCode = requestBean.getRequestParamString("seatCode");
        Integer seatType = requestBean.getRequestParamInteger("seatType");
        Integer sellerId = requestBean.getRequestParamInteger("g_sellerid");
        Map<String, Object> priorityMap = new HashMap<>();
        priorityMap.put("seatCode",seatCode);
        priorityMap.put("seatType",seatType);
        priorityMap.put("sellerId",sellerId);
        ResponseBean responseBean = requestBean.getResponseBean();
        List<Map<String, Object>> priorityList = wxIndexDataDao.queryIndex(priorityMap);
        responseBean.addResultItem("priorityList", priorityList);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 分类推荐
     * @param requestBean
     * @return
     */
    public ResponseBean queryCategoryPriority(RequestBean requestBean) {
        Date now=new Date();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String seatCode = requestBean.getRequestParamString("seatCode");
        Integer seatType = requestBean.getRequestParamInteger("seatType");
        Integer sellerId = requestBean.getRequestParamInteger("g_sellerid");
        Map<String, Object> priorityMap = new HashMap<>();
        priorityMap.put("seatCode",seatCode);
        priorityMap.put("seatType",seatType);
        priorityMap.put("sellerId",sellerId);
        ResponseBean responseBean = requestBean.getResponseBean();
        List<Map<String, Object>> categoryPriority = wxIndexDataDao.queryCategoryPriority(priorityMap);
        responseBean.addResultItem("categoryPriority", categoryPriority);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    public ResponseBean queryIndexProList(RequestBean requestBean) {
        int page=requestBean.getRequestParamInteger("page",0);
        ResponseBean responseBean = requestBean.getResponseBean();
        List<Map<String, Object>> proList = new ArrayList<>();
        Map<String, Object> proInfo = new HashMap<>();
        proInfo.put("id", "测试图片");
        proInfo.put("name", "测试图片"+page);
        proInfo.put("intro", "测试图片");
        proInfo.put("price_yh", "33");
        proInfo.put("price", "34");
        proInfo.put("shiyong", "5");
        proInfo.put("photo_x", "20171211163540.png");
        proList.add(proInfo);
        proInfo = new HashMap<>();
        proInfo.put("id", "测试图片");
        proInfo.put("name", "测试图片"+page);
        proInfo.put("intro", "测试图片");
        proInfo.put("price_yh", "33");
        proInfo.put("price", "34");
        proInfo.put("shiyong", "5");
        proInfo.put("photo_x", "20171205203015.png");
        proList.add(proInfo);
        proInfo = new HashMap<>();
        proInfo.put("id", "测试图片");
        proInfo.put("name", "测试图片"+page);
        proInfo.put("intro", "测试图片");
        proInfo.put("price_yh", "33");
        proInfo.put("price", "34");
        proInfo.put("shiyong", "5");
        proInfo.put("photo_x", "20171205205256.png");
        proList.add(proInfo);

        responseBean.addResultItem("prolist",proList);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }
}
